package com.opennews.openplatform

import groovy.transform.CompileStatic
import org.springframework.http.HttpStatus

@CompileStatic
class AppErrorReportController extends BaseController {
    static allowedMethods = [
        send: "POST"
    ]

    AppErrorReportService appErrorReportService

    // region: Get actions.
    def index() {
        render("AppErrorReportController")
    }
    // endregion

    // region: Post actions.
    def send() {
        def requestBodyData = getRequestBodyData() as Map<String, ?>
        def claims = getClaims()

        // If user is authenticated we need to get username.
        if (claims != null) {
            requestBodyData.put("username", claims.username)
        }

        appErrorReportService.save(requestBodyData)

        sendStatusResponse(HttpStatus.NO_CONTENT)
    }
    // endregion
}
